package com.xinchuang.controller.targetSystem.damage;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.comment.R;
import com.xinchuang.service.targetSystem.damage.IDictionaryTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 公共接口模块
 * @Author: thh
 * @Date: 2024/5/1 9:58
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/common")
@Api(value = "公共接口模块", tags = "公共接口模块")
public class CommonController {

    private final IDictionaryTableService dictionaryTableService;


    /**
     * 获取字段类型接口
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/getFieldTypeList")
    @ApiOperation("获取字段类型接口")
    public R getFieldTypeList(@RequestBody JSONObject jsonObject) {
        return JSON.parseObject(dictionaryTableService.getFieldTypeList(jsonObject), R.class);
    }

    /**
     * 获取显示类型接口
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/getShowTypeList")
    @ApiOperation("获取显示类型接口")
    public R getShowTypeList(@RequestBody JSONObject jsonObject) {
        return JSON.parseObject(dictionaryTableService.getShowTypeList(jsonObject), R.class);
    }

    /**
     * 根据字典类型获取字典列表接口
     *
     * @param type
     * @return
     */
    @GetMapping("/getDictList")
    @ApiOperation("根据字典类型获取字典列表接口")
    public R getDictList(@RequestParam(value = "type") String type) {
        if (StringUtils.isNotBlank(type) && type.contains("=")) {
            type = type.split("=")[1];
        }
        return R.data(dictionaryTableService.getDictList(type));
    }

}
